<!DOCTYPE html>  <!-- jQuery -->
<html>
<head>
  <meta charset="UTF-8">
  <!-- 引入jQuery -->
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <style>
    .modal {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 1000;
      display: none;
    }

    .modal.active {
      display: block;
    }

    .modal-backdrop {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(45deg, rgba(255, 192, 203, 0.3), rgba(173, 216, 230, 0.3));
      cursor: pointer;
    }

    .modal-dialog {
      position: relative;
      width: auto;
      max-width: 280px;
      margin: 100px auto;
    }

    .modal-content {
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 0 12px rgba(0, 0, 0, 0.15);
      padding: 16px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .loading-image {
      height: 150px;
      display: block;
      margin: 0 auto 12px;
    }

    .loading-text {
      text-align: center;
      margin: 0 0 15px 0;
    }

    .modal-footer {
      margin-top: 15px;
    }
  </style>
</head>
<body>
<button id="openModal">显示模态框</button>

<div id="myModal" class="modal">
  <div class="modal-backdrop"></div>
  <div class="modal-dialog">
    <div class="modal-content">
      <p class="loading-text">我是jQuery做的模态框</p>
      <img src="../resources/images/whitecat_3.gif" class="loading-image">
      <div class="modal-footer">
        <button id="closeModal">关闭</button>
      </div>
    </div>
  </div>
</div>

<script>
  // 等待DOM加载完成
  $(document).ready(function() {
    // 缓存元素
    var $modal = $('#myModal');

    // 打开模态框
    $('#openModal').click(function() {
      $modal.addClass('active');
      $('body').css('overflow', 'hidden');
    });

    // 关闭模态框的函数
    function closeModal() {
      $modal.removeClass('active');
      $('body').css('overflow', '');
    }

    // 点击关闭按钮关闭
    $('#closeModal').click(closeModal);

    // 点击背景关闭
    $modal.find('.modal-backdrop').click(closeModal);

    // 按ESC键关闭
    $(document).keydown(function(event) {
      if (event.key === 'Escape' && $modal.hasClass('active')) {
        closeModal();
      }
    });
  });
</script>
</body>
</html>
